package face.pay.rocket.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import face.pay.profit.IprofitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Auther: zkj
 * @Date: 2019/8/2 16:29
 * @Description:
 */
@Component
@Slf4j
public class ProfitMessageListener implements MessageListener {

    @Resource(name = "profitCacheService")
    private IprofitService iprofitService;

    @Override
    public Action consume(Message message, ConsumeContext context) {


        System.out.println("Receive: " + message);
        try {

            String body = new String(message.getBody());
            this.iprofitService.profit(body);

        } catch (Exception e) {
            log.error("分佣消息 消费异常",e);
            //消费失败
        }
        return Action.CommitMessage;
    }
}
